package com.fjw.mapper;

import com.fjw.pojo.Material;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MaterialMapper {
    //新增
    @Insert("insert into Material(title,content,category,author) values (#{title},#{content},#{category},#{author})")
    void add(Material material);

    //通过id查找
    @Select("select * from Material where id=#{id}")
    Material findById(Integer id);

    //通过类别查找
    @Select("select * from Material where category=#{category}")
    List<Material> findByCategory(String category);

    //通过作者查找
    @Select("select * from Material where author=#{author}")
    List<Material> findByAuthor(Integer author);

    //通过ID删除
    @Delete("delete from Material where id=#{id}")
    void deleteById(Integer id);

    //通过ID更新
    @Update("update Material set title=#{title},content=#{content},category=#{category} where id=#{id}")
    void updateById(Material material);

    //查找全部
    @Select("select * from Material")
    List<Material> getAll();

}
